/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpaintball;

//import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author ondra
 */
public class Position {

    private Point2D point;
    private Dimension dimension;

    private Point2D pole;
    private double angle;

    Position(int _x, int _y, int _width, int _height, int poleX, int poleY, double _angle) {

        point = new Point2D.Double(_x, _y);
        dimension = new Dimension(_width,_height);
        pole = new Point2D.Double(poleX, poleY);
        angle = _angle;


    }

    Position(Position p) {

        point = new Point2D.Double(p.getPoint().getX(), p.getPoint().getY());
        dimension = new Dimension(p.getWidth(), p.getHeight());
        pole = new Point2D.Double(p.getPole().getX(), p.getPole().getY());
        angle = p.getAngle();

    }

    /**
     * @return the x
     */
    public int getX() {
        return (int) getPoint().getX();
    }

    /**
     * @return the y
     */
    public int getY() {
        return (int) getPoint().getY();
    }

    /**
     * @return the height
     */
    public int getHeight() {
        return (int) getDimension().getHeight();
    }

    /**
     * @return the width
     */
    public int getWidth() {
        return (int) getDimension().getWidth();
    }

    public Area getArea() {

        Area ret = new Area(new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight()));

        //if(getPole() == null) {
        //    return ret;
        //}
        AffineTransform af = new AffineTransform();
        af.rotate(getAngle(),getPoleX(), getPoleY());
        //af.translate(-getPoleX(), -getPoleY());

        return ret.createTransformedArea(af);
    }

    void relativeMove(double _x, double _y) {
        getPoint().setLocation(getPoint().getX()+_x,getPoint().getY()+_y);
    }
    int getPoleX() {
        return (int) getPole().getX() + getX();
    }
    int getPoleY() {
        return (int) getPole().getY() + getY();
    }
    double getAngle() {
        return angle;
    }

    /**
     * @return the point
     */
    public Point2D getPoint() {
        return point;
    }

    /**
     * @return the dimension
     */
    public Dimension getDimension() {
        return dimension;
    }

    /**
     * @return the pole
     */
    public Point2D getPole() {
        return pole;
    }
    public void setRotation(int x, int y) {
        angle = Math.atan2(getPoleY()-y,getPoleX()-x)-Math.PI/2;
    }

}
